<template>
  <div id="searchbox">
    <div id="search">
      <input
        type="text"
        placeholder="Search..."
        ref="enter"
        v-model="searchcontent"
        maxlength="25"
      /><img src="@/assets/img/icon/search.svg" ref="img" title="点击搜索" />
    </div>
  </div>
</template>

<script>
import Bus from "@/assets/js/bus.js";
import { DeBounce } from "@/assets/js/DeBounce";
export default {
  name: "Search",
  data() {
    return {
      searchcontent: "",
    };
  },
  methods: {
    SearchEnter(event) {
      let target = event || window.event;
      if (target && target.keyCode == 13) {
        this.SearchEnterAfter();
      }
    },
    SearchEnterAfter() {
      this.searchcontent != ""
        ? console.log("ok")
        : Bus.$emit("warning", "请输入搜索内容");
    },
  },
  mounted() {
    this.$refs.enter.addEventListener(
      "keyup",
      DeBounce(this.SearchEnter, 1000, true)
    );
    this.$refs.img.addEventListener(
      "click",
      DeBounce(this.SearchEnterAfter, 1000, true)
    );
  },
  computed: {},
};
</script>

<style scoped>
#searchbox {
  display: flex;
  flex-direction: column;
  letter-spacing: 0.5rem;
  margin-top: -7px;
  height: 35px;
  position: relative;
  width: 250px;
}
@media screen and (max-width: 900px) {
  #searchbox {
    flex: none;
  }
}
#search {
  border-radius: 5px;
  overflow: hidden;
  padding: 0px;
  width: 250px;
  height: 35px;
  background-color: #393a3e;
  position: relative;
}

#search input {
  border-radius: 70px;
  margin: 0px;
  height: 30px;
  width: 80%;
  outline: none;
  background-color: #393a3e;
  color: white;
  font-weight: 400;
  letter-spacing: 0.01rem;
  font-size: 0.7rem;
  padding-left: 10px;
  border: none;
  padding-right: 0px;
}

#search input::-webkit-input-placeholder {
  color: white;
}

#search img {
  position: absolute;
  width: 25px;
  top: 5px;
  cursor: pointer;
}

#search img:hover {
  opacity: 0.7;
}
</style>
